(require (planet schematics/schemeunit:3))

(define (new-if predicate then-clause else-clause)
  (cond (predicate then-clause)
        (else else-clause)))

(define (sqrt-iter guess x)
  (new-if (good-enough? guess x)
          guess
          (sqrt-iter (improve guess x)
                     x)))

(define (improve guess x)
  (average guess (/ x guess)))

(define (average x y)
  (/ (+ x y) 2))

(define (good-enough? guess x)
  (< (abs (- (square guess) x)) 0.001))

(define (sqrt x)
  (sqrt-iter 1.0 x))

(sqrt 9)

;é expandido para

(sqrt-iter 1.0 9)

;é expandido para

(new-if (good-enough? 1.0 9)
          1.0
          (sqrt-iter (improve 1.0 9)
                     9))

;agora todos os parâmetros serão avaliados (pelo if ser customizado e não
;apresentar "short-circuit") incluindo a chamada do sqrt-iter, o que causará
;uma recursão infinita.
